<template>
  <el-container>
    <div class="header">
      <div class="title">苏小课后台管理系统</div>
      <div class="user-info">
        <div class="notification">
          <i class="bell-icon">🔔</i>
          <span class="badge">1</span>
        </div>
        <div class="user">您好，管理员！</div>
        <div class="actions">
          <a href="./login.html">退出</a>
        </div>
      </div>
    </div>
    <el-header>
      <div class="breadcrumb-nav">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item @click='navigateTo("adminHome/home.html")'>首页</el-breadcrumb-item>
          <el-breadcrumb-item>待审核课程</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </el-header>

    <el-main>
      <div class="content-wrapper">
        <el-table :data="pendingCourses" style="width: 100%">
          <el-table-column prop="name" label="课程名称" width="180"></el-table-column>
          <el-table-column prop="teacher" label="授课老师" width="180"></el-table-column>
          <el-table-column prop="startTime" label="开始时间" width="180"></el-table-column>
          <el-table-column prop="endTime" label="结束时间" width="180"></el-table-column>
          <el-table-column prop="duration" label="课时" width="100"></el-table-column>
          <el-table-column prop="description" label="课程描述"></el-table-column>
          <el-table-column label="操作" width="180">
            <template v-slot="{ row }">
              <el-button type="success" @click="approveCourse(row)">通过</el-button>
              <el-button type="danger" @click="rejectCourse(row)">驳回</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-main>
  </el-container>
</template>


<script setup>
import { useUserStore } from "../../store/user.js";
let userStore = useUserStore();
userStore.storeInit();

import "../../../public/header.css";

import { ref } from "vue";
import axios from 'axios';
let pendingCourses = ref(null);

const getPendingCourses = () => {
  axios({
    url: "http://localhost:9090/pendingCourses",
    method: "GET",
  })
    .then((response) => {
      // console.log("获取待审核列表", response);
      pendingCourses.value = response.data;
      // console.log(pendingCourses);
    })
    .catch((error) => {
      console.log(error);
      // 可在此添加失败后提示
    });
};
getPendingCourses()

function approveCourse(course){
  axios({
    url: "http://localhost:9090/approveCourse",
    method: "POST",
    data: course,
  })
    .then((response) => {
      console.log(response);
      // 可在此添加成功后提示
      location.reload();
    })
    .catch((error) => {
      console.log(error);
      // 可在此添加失败后提示
    });
}

function navigateTo(page) {
  window.location.href = `/src/pages/${page}`;
}
</script>

<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #fff;
  border-bottom: 1px solid #ddd;
}

.header .title {
  font-size: 24px;
  color: #1e90ff;
}

.header .user-info {
  display: flex;
  align-items: center;
}

.header .user-info .notification {
  margin-right: 20px;
  position: relative;
}

.header .user-info .notification .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: red;
  color: #fff;
  border-radius: 50%;
  padding: 2px 5px;
  font-size: 12px;
}

.header .user-info .user {
  margin-right: 10px;
  color: #333;
}

.header .user-info .actions a {
  margin: 0 5px;
  color: #1e90ff;
  text-decoration: none;
}

.el-header {
  background-color: #fff;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.breadcrumb-nav {
  padding: 0 20px;
}

.content-wrapper {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

</style>
